﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Tsanie.DmPoster.Utils;
using System.Drawing.Text;

namespace Tsanie.DmPoster {
    public partial class ConfigForm : Form {
        public ConfigForm() {
            InitializeComponent();
            foreach (FontFamily family in new InstalledFontCollection().Families) {
                comboFonts.Items.Add(family.Name);
            }
        }
        private void Reload() {
            textPlayTime.Text = Config.m_playTime.ToString();
            comboFontsize.Text = Config.m_fontsize.ToString();
            textColor.Text = StringUtil.StringFromColorInt(Config.m_color);
            labelColor.ForeColor = StringUtil.ColorFromInt(Config.m_color);
            textHttpBase.Text = Config.m_HttpBase;
            textCacheSeconds.Text = Config.m_CacheSeconds.ToString();
            comboFonts.Text = Config.m_Fontname;
            keyEdit.Key = Config.m_Edit;
            keyEditTime.Key = Config.m_EditTime;
            keyEditColor.Key = Config.m_EditColor;
            keyEditSize.Key = Config.m_EditSize;
            keyEditMsg.Key = Config.m_EditMsg;
            trackAlpha.Value = Config.m_Alpha;
        }
        private void ConfigForm_Load(object sender, EventArgs e) {
            Reload();
        }
        private void buttonCancel_Click(object sender, EventArgs e) {
            this.Close();
        }
        private void buttonReset_Click(object sender, EventArgs e) {
            Reload();
        }
        private void buttonOk_Click(object sender, EventArgs e) {
            Config.SetValue("PlayTime", textPlayTime.Text);
            Config.SetValue("Fontsize", comboFontsize.Text);
            Config.SetValue("Color", StringUtil.IntColorFromString(textColor.Text).ToString());
            Config.SetValue("HttpBase", Config.EnsureHttp(textHttpBase.Text));
            Config.SetValue("CacheSeconds", textCacheSeconds.Text);
            Config.SetValue("Fontname", comboFonts.Text);
            Config.SetValue("EditKey", ((int)keyEdit.Key).ToString());
            Config.SetValue("EditTimeKey", ((int)keyEditTime.Key).ToString());
            Config.SetValue("EditColorKey", ((int)keyEditColor.Key).ToString());
            Config.SetValue("EditSizeKey", ((int)keyEditSize.Key).ToString());
            Config.SetValue("EditMsgKey", ((int)keyEditMsg.Key).ToString());
            Config.SetValue("Alpha", trackAlpha.Value.ToString());
            this.Close();
        }
        private void textColor_TextChanged(object sender, EventArgs e) {
            try {
                labelColor.ForeColor = StringUtil.ColorFromString(textColor.Text);
            } catch { }
        }
        private void labelColor_Click(object sender, EventArgs e) {
            colorDialog.Color = labelColor.ForeColor;
            if (colorDialog.ShowDialog(this) == System.Windows.Forms.DialogResult.OK) {
                labelColor.ForeColor = colorDialog.Color;
                textColor.Text = StringUtil.StringFromColor(colorDialog.Color);
            }
        }
    }
}
